package com.leo.employ.controller

import com.leo.employ.pojo.User
import com.leo.employ.service.UserService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import javax.servlet.http.HttpServletRequest

@RestController
@RequestMapping("user")
class UserController {

    @Autowired
    lateinit var userService: UserService

    @RequestMapping("ist")
    fun findAllUser(request:HttpServletRequest): MutableList<User> {
        request.session.setAttribute("userid", "1")
        print(request.session.id)
        return userService.findAllUser()
    }

    @PostMapping("add")
    fun insertUser(@RequestBody user: User) {
        userService.insertUser(user)
    }

    @PostMapping("check")
    fun checkUser(@RequestBody user: User): User? {
        return userService.checkUser(user.phone!!)
    }
}